Explicit.in - A Web Site for Adults or just a Generic Dictionary Word?

The Clean Code Talks - "Global State and Singletons" Video

Google Tech Talks
November 13, 2008

ABSTRACT

The Clean Code Talk Series

Speaker: Misko Hevery

Add to Yahoo MyWeb Add to Yahoo Buzz Add to Yahoo Bookmarks Stumble on StumbleUpon Add to Reddit Add to Google Bookmarks Add to Newsvine Add to MySpace Add to Windows Live Add to Furl Add to Fark Add to Facebook Submit to Digg Add to Delicious Add to Blinklist

Comments on "The Clean Code Talks - "Global State and Singletons""

Damn, good I never ...
Damn, good I never saw such? Singleton abusing.

thegoodteacher(dot) ...
thegoodteacher(dot)com?

Did this ass? ...
Did this ass? really just call a computer a finite-state machine? Is he high?

Whatever method ...
Whatever method needs this 'current time of day' should have the time? of day passed into it; so that you can run your test with a known time of day. Simply having deep areas of your code pulling various outside values without explicit control is asking for testing trouble.

What are you going ...
What are you going to test it against??

But what if? I have ...
But what if? I have a method that, say, gets the current time of day? Even given the exact same input, it will, of course, return different values depending on external conditions. What's wrong with that? It seems perfectly intuitive and testable to me!

There is a ton of ...
There is a ton of great design information in this talk.?

@blenderpanzi @ ...
@blenderpanzi @magwo I think you guys are saying the same thing. :p If x == y? && f(x) != f(y), f is dependent on global state. If f modifies state, it has a side effect.

Well from a ...
Well from a theoretical point of view there are basically two concepts: functional and logic orientated. So I guess all existing languages have to be described with one of these? two (lambda calculus is used as the theoretical background for most programming languages), which explains why my professor said in a theoretical lecture that global state (or even mutable objects) are basically side effects. :)

This is true in a ...
This is true in a purely functional language. In object-oriented languages with mutable objects, side effects do not really imply global state. Objects are created in local scopes, and if two objects are created equally, you should get the same result from obj1.f(x) as obj2.f(x), as well as obj1.f(y) and obj2.f(y)? if x==y. Unless you have global state, like static variables, random generators (that are commonly based on the global variable known as the clock) and so on.

AFAIK: if x == y && ...
AFAIK: if x == y && f(x) != f(y) then there is a side effect. Having global state (or just object oriented programming with mutable objects)? you get such a situation, because there is a hidden parameter. But maybe I did understand something wrong.

That is not correct ...
That is not correct. They are obviously not the same thing IMO. However? having a mutable global state makes any code anywhere _potentially_ side effect laden, to an unknown extent, because the state changes can propagate between singletons etc. If you do not have global state, the side effects can only happen in the set of objects that you are currently testing in isolation, so they can be expected and checked for correctness.

Well, one of my ...
Well, one of my professor said global state equals side effects, mathematically spoken.? I just believed him.

better use charge(- ...
better use charge(-100) ;-)?

Actually it's not ...
Actually it's not at all about side effects. Side effects do? not present a big problem to testability of code, but global state (global side effects) does.

At 24:10 again: He ...
At 24:10 again: He wants a functional and sideeffect free language. In? haskell you CAN change the order of expressions! Why isn't he saying that he does not like OOP languages but would like to use a functional language?

I'm at 8:30 and ...
I'm at 8:30 and wonder if he will name the child by its? name in this talk and say: SIDEEFFECTS! He wants a sideeffect free language. He should use haskell.

God I? learned this ...
God I? learned this the hard way at my internship. It DOES drive you crazy...

i learned - next ...
i learned - next time I test a credit card system? - I will use charge(1) :)

SECRETLY!?
SECRETLY!?

static data is ok ...
static data is ok if it an implementation detail and it doesn't change? the interface

I used the same ...
I used the same term that wikipedia uses, IoC, which also states that "Dependency Injection" (same thing, different name? (of dependency inversion)) is a part of IoC. Could you please elaborate? From where does an object get its references if not? through the constructor/setters or the global environment in a language like Java? Of course, I don't take regular method arguments into consideration now, but that's also a place to where dependencies can be moved.

Side-effects are ...
Side-effects are probably the heart of the matter, and pure functional programming does remedy that. But still, what I think the point was is "Inversion of Control"; that objects' relations should? be well thought out and explicit. That is, it's very bad to use global state as a means to let objects find its environment (and unlike scheme etc., java has got only the object's state and the global environment). Also, there's long been a notion of "mutators"/"inspectors"/etc. kinds of methods.

Don't you think ...
Don't you think that Aspect- Oriented programming is the best solution for complex initialization? mechanism with both init and finalization methods to be called.

Seriously SFTU and ...
Seriously SFTU and stop? interrupting.

The part about the ...
The part about the deceptive API is a good summary of why not to have global (mutable) state in any form. Singleton-ness is a big design decision to make, and should never be enforced by a class. It's better to let the user of the class make that decision. It may be tempting to let objects discover their environment? through the ether that is the global name space. But objects should only know what you let them know. Interesting thought to make a separation of "Value" and "Service" objects.

Explicit.in - A Web Site for Adults or just a Generic Dictionary Word?



Privacy Policy | Copyright/Trademark Notification
www.cellulartrendz.com